package org.jeecg.activiti.ActivitClass;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.TaskService;
import org.activiti.engine.delegate.*;

import org.activiti.engine.task.Task;
import org.jeecg.activiti.entity.ActReModelFormDeployment;
import org.jeecg.activiti.service.IActReModelFormDeploymentService;
import org.jeecg.activiti.service.impl.ActReModelFormDeploymentServiceImpl;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

@Component
public class UserForm implements ExecutionListener {

@Resource
    private IActReModelFormDeploymentService iActReModelFormDeploymentService;

//    public void execute(DelegateExecution delegateExecution) {
//        String assignee="admin";
//        String keyid="t123456";
//        ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
//        RepositoryService repositoryService=engine.getRepositoryService();
//
//        // 任务查询 需要获取一个 TaskService 对象
//        TaskService taskService = engine.getTaskService();
//
//        // 根据流程的key和任务负责人 查询任务
//        List<Task> list = taskService.createTaskQuery()
//                .processDefinitionKey(keyid)
//                .taskAssignee(assignee)
//                .list();
//        // 输出当前用户具有的任务
//        for (Task task : list) {
//            System.out.println(repositoryService.getModel(task.getProcessInstanceId()));
//            System.out.println("流程实例id：" + task.getProcessInstanceId());
//            System.out.println("任务id:" + task.getId());
//            System.out.println("任务负责人：" + task.getAssignee());
//            System.out.println("任务名称：" + task.getName());
//        }
//    }


    @Override
    public void notify(DelegateExecution delegateTask) {

        String assignee="admin";
        String keyid="t123456";
        ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
        System.out.println("taskListener");
        // 任务查询 需要获取一个 TaskService 对象
        TaskService taskService = engine.getTaskService();
        RepositoryService repositoryService= engine.getRepositoryService();
        String processDefinitionId=delegateTask.getProcessDefinitionId();
        System.out.println("processDefinitionId:" + processDefinitionId);
//        QueryWrapper<ActReModelFormDeployment> queryWrapper=new QueryWrapper<ActReModelFormDeployment>()
//                .eq("process_Definition_Id", processDefinitionId);
//        List<ActReModelFormDeployment> list=iActReModelFormDeploymentService.list(queryWrapper);
//        for (ActReModelFormDeployment actReModelFormDeployment : list){
//            System.out.println(actReModelFormDeployment.getHtmlJson());
//        }
    }
}
